<?php

/**
 * This is the model class for table "DiemHK1".
 *
 * The followings are the available columns in table 'DiemHK1':
 * @property integer $idDHK1
 * @property string $MaQT
 * @property string $MaMH
 * @property integer $D0105
 * @property integer $D0610
 * @property double $GK1
 * @property integer $D1114
 * @property integer $D1518
 * @property double $CK1
 * @property double $HLM1
 *
 * The followings are the available model relations:
 * @property MonHoc $maMH
 * @property QuaTrinh $maQT
 */
class DiemHK1 extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return DiemHK1 the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'DiemHK1';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('D0105, D0610, D1114, D1518', 'numerical', 'integerOnly'=>true),
			array('GK1, CK1, HLM1', 'numerical'),
			array('MaQT, MaMH', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idDHK1, MaQT, MaMH, D0105, D0610, GK1, D1114, D1518, CK1, HLM1', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'maMH0' => array(self::BELONGS_TO, 'MonHoc', 'MaMH'),
			'maQT0' => array(self::BELONGS_TO, 'QuaTrinh', 'MaQT'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idDHK1' => 'id',
			'MaQT' => 'MaQT',
			'MaMH' => 'MaMH',
			'D0105' => '0105',
			'D0610' => '0610',
			'GK1' => 'GK1',
			'D1114' => '1114',
			'D1518' => '1518',
			'CK1' => 'CK1',
			'HLM1' => 'HLM1',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idDHK1',$this->idDHK1);
		$criteria->compare('MaQT',$this->MaQT,true);
		$criteria->compare('MaMH',$this->MaMH,true);
		$criteria->compare('D0105',$this->D0105);
		$criteria->compare('D0610',$this->D0610);
		$criteria->compare('GK1',$this->GK1);
		$criteria->compare('D1114',$this->D1114);
		$criteria->compare('D1518',$this->D1518);
		$criteria->compare('CK1',$this->CK1);
		$criteria->compare('HLM1',$this->HLM1);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function getTenNH()
        {
            $modelQT = QuaTrinh::model()->findByPk($this->MaQT);
            $modelNH = NamHoc::model()->findByPk($modelQT["MaNH"]);
            return $modelNH["TenNH"];
        }
}